home *** CD-ROM | disk | FTP | other *** search
/ The Atari Compendium / The Atari Compendium (Toad Computers) (1994).iso / files / umich / sound / players / naudio.lzh / naudio / examples / ex1.c < prev    next >
C/C++ Source or Header  |  1993-11-30  |  6KB  |  173 lines

  1. #include "ex.h"
  2. #include <aes.h>
  3. #include <string.h>
  4. #include <naudio\naudio.h>
  5.  
  6. /* This little example is an example of BAD C-Programming, and BAD
  7.    GEM-Programming, since it does NO error checking. On the other
  8.    hand the NAUDIO code is done properly, what you care about any-
  9.    way. The lack of error checking is to keep the source short,
  10.    as to not obscure the NAUDIO functionality.
  11.  */
  12. #define WTYPE  (NAME | CLOSER | MOVER)
  13.  
  14.  
  15. static void join( char *dst, char *path, char * file)
  16. {
  17.    strcpy( dst, path);
  18.    strcpy( strrchr( dst, '\\') + 1, file);
  19. }
  20.  
  21.  
  22. main()
  23. {
  24.    OBJECT         *tree, *menu;
  25.    int            id;
  26.    unsigned int   ev;
  27.    int            x, y, w, h, dmy;
  28.    int            mbuf[ 8];
  29.    auto char      path[ 128],
  30.                   filename[ 32],
  31.                   full[ 256];
  32.    n_sample       *p = 0;
  33.    channel        *q = 0;
  34.  
  35.  
  36.    appl_init();
  37.    graf_mouse( 0, NULL);
  38.                      /* inialize NAUDIO for SAMPLE playing  */
  39.    naudio_init();    /* the standard 3-step                 */
  40.    naudio_some();
  41.    if( naudio_engine( SAMPLES) < 0)
  42.    {
  43.       form_alert( 1, "[1][NAUDIO Initialization failed!][ EXIT ]");
  44.       appl_exit();
  45.       return( -1);
  46.    }
  47.                      /* now boring GEM stuff... */
  48.    rsrc_load( "ex.rsc");
  49.    rsrc_gaddr( R_TREE, T_DIAL, &tree);
  50.    rsrc_gaddr( R_TREE, T_MENU, &menu);
  51.    menu_bar( menu, 1);
  52.    wind_calc( WC_BORDER, WTYPE, tree->ob_x, tree->ob_y,
  53.                                 tree->ob_width, tree->ob_height,
  54.                                 &x, &y, &w, &h);
  55.    id = wind_create( WTYPE, x, y, w, h);
  56.    wind_open( id, x, y, w, h);
  57.    wind_set( id, WF_NAME, "NAUDIO-EX1");
  58.  
  59.    for( ;;)
  60.    {
  61.       ev = evnt_multi( MU_BUTTON | MU_MESAG, 2, 3, 1,
  62.                        0, 0, 0, 0, 0,
  63.                        0, 0, 0, 0, 0,
  64.                        mbuf,
  65.                        0, 0,
  66.                        &x, &y, &dmy, &dmy, &dmy, &dmy);
  67.  
  68.       if( ev & MU_BUTTON)
  69.       {
  70.          int   no;
  71.  
  72.          if( (no = objc_find( tree, 0, 16, x, y)) >= 0 &&
  73.              ! form_button( tree, no, 1, &dmy))
  74.          {
  75.             objc_change( tree, no, 0, tree->ob_x, tree->ob_y,
  76.                                       tree->ob_width, tree->ob_height,
  77.                                       0, SELECTED);
  78.             switch( no)
  79.             {
  80.                            /* LOAD button was pressed. Ask user for
  81.                               filename and proceed if OK was pressed
  82.                               in the fileselector. Since we will
  83.                               throw away the old sample (or none the
  84.                               first time), we must also discard any
  85.                               possibly active channel. Set q to 0 to
  86.                               remember this. Finally load in the s
  87.                               sample from pathname `full'.
  88.                            */
  89.                case D_LOAD :
  90.                   fsel_input( path, filename, &dmy);
  91.                   if( dmy)
  92.                   {
  93.                      if( q)
  94.                      {
  95.                         channel_delete( q);
  96.                         q = 0;
  97.                      }
  98.                      if( p)
  99.                         nsample_free( p);
  100.                      join( full, path, filename);
  101.                      if( ! (p = nsample_load( full)))
  102.                         form_alert( 1, "[2][Load failed][ OK ]");
  103.                   }
  104.                   break;
  105.  
  106.                            /* PLAY button has been pressed. So stop the
  107.                               engine. And then start it anew.
  108.                               If any channel was allocated, delete it.
  109.                               Then play sample on the new channel, if
  110.                               one has been loaded.
  111.                            */
  112.                case D_PLAY :
  113.                   naudio_stop();    /* 1st time superflous, but harmless*/
  114.                   naudio_start( 0);
  115.                   if( q)
  116.                      channel_delete( q);
  117.                   if( p)
  118.                      q = nsample_play( p, 0L, NAUDIO_MAX_VOL, 1);
  119.                   break;
  120.  
  121.                            /* SAVE button was pressed. So get the filename
  122.                               from fsel_input and save the sample under
  123.                               the `full' pathname.
  124.                             */
  125.                case D_SAVE :
  126.                   if( p)
  127.                   {
  128.                      fsel_input( path, filename, &dmy);
  129.                      if( dmy)
  130.                      {
  131.                         join( full, path, filename);
  132.                         if( nsample_save( full, p, 'NSVX'))
  133.                            form_alert( 1, "[2][Save failed][ OK ]");
  134.                      }
  135.                   }
  136.                   break;
  137.             }
  138.          }
  139.       }
  140.  
  141.          /* handle other GEM events */
  142.       if( ev & MU_MESAG)
  143.       {
  144.          switch( mbuf[ 0])
  145.          {
  146.             case MN_SELECTED :
  147.             case WM_CLOSED :
  148.                goto done;
  149.  
  150.             case WM_MOVED :
  151.                wind_set( id, WF_CURRXYWH, mbuf[4], mbuf[5], mbuf[6], mbuf[7]);
  152.                wind_calc( WC_WORK, WTYPE, mbuf[4], mbuf[5], mbuf[6], mbuf[7],
  153.                                           &tree->ob_x, &tree->ob_y,
  154.                                           &tree->ob_width, &tree->ob_height);
  155.                break;
  156.  
  157.             case WM_REDRAW :
  158.                objc_draw( tree, 0, 16, mbuf[ 4], mbuf[ 5], mbuf[ 6], mbuf[ 7]);
  159.          }
  160.       }
  161.    }
  162. done:
  163.    naudio_done();             /* IMPORTANT: MUST DO THIS BEFORE EXITING */
  164.    menu_bar( menu, 0);
  165.    wind_close( id);
  166.    wind_delete( id);
  167.    appl_exit();
  168.    return( 0);
  169. }
  170.  
  171.  
  172.  
  173.